/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 * 注意：
 * 本软件为www.joolun.com开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */

package com.joolun.cloud.common.alioss.config;

import com.joolun.cloud.common.alioss.service.AliOssTemplate;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * aliOSS 自动配置类
 * @author JL
 */
@AllArgsConstructor
@EnableConfigurationProperties({AliOssConfigProperties.class})
public class AliOssAutoConfiguration {
	private final AliOssConfigProperties aliOssConfigProperties;

	@Bean
	@ConditionalOnMissingBean(AliOssTemplate.class)
	AliOssTemplate template() {
		return new AliOssTemplate(
				aliOssConfigProperties.getAccessKeyId() ,
				aliOssConfigProperties.getAccessKeySecret(),
				aliOssConfigProperties.getEndpoint(),
				aliOssConfigProperties.getBucket(),
				"https://" + aliOssConfigProperties.getBucket() + "." + aliOssConfigProperties.getEndpoint()
		);
	}

}
